package com.mofang.ticketing.user.serve.role.controller;


import com.mofang.ticketing.common.core.dto.PrimaryIdDTO;
import com.mofang.ticketing.common.core.page.PageResult;
import com.mofang.ticketing.common.core.result.Result;
import com.mofang.ticketing.common.core.urls.user.role.RoleUrl;
import com.mofang.ticketing.common.log.SystemLog;
import com.mofang.ticketing.user.serve.role.dto.request.RoleAddReqDTO;
import com.mofang.ticketing.user.serve.role.dto.request.RoleListPageReqDTO;
import com.mofang.ticketing.user.serve.role.dto.request.RoleUpdateReqDTO;
import com.mofang.ticketing.user.serve.role.dto.response.MerchantRoleSelectRespDTO;
import com.mofang.ticketing.user.serve.role.dto.response.RoleDetailRespDTO;
import com.mofang.ticketing.user.serve.role.dto.response.RoleListPageRespDTO;
import com.mofang.ticketing.user.serve.role.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LGC
 */
@Api(tags = "角色管理")
@RestController
public class RoleController {

    @Resource
    private RoleService roleService;

    @ApiOperation(value = "角色详情")
    @PostMapping(value = RoleUrl.ROLE_DETAIL)
    public Result<RoleDetailRespDTO> roleDetail(@RequestBody @Validated PrimaryIdDTO dto) {
        return Result.success(roleService.roleDetail(dto));
    }


    @ApiOperation(value = "平台角色分页列表")
    @PostMapping(value = RoleUrl.PLATFORM_ROLE_LIST_PAGE)
    public Result<PageResult<RoleListPageRespDTO>> platformRoleListPage(@RequestBody @Validated RoleListPageReqDTO dto) {
        return Result.page(PageResult.getPageResult(roleService.roleListPage(dto)));
    }

    @SystemLog
    @ApiOperation(value = "平台角色新增")
    @PostMapping(value = RoleUrl.PLATFORM_ROLE_ADD)
    public Result<Void> platformRoleAdd(@RequestBody @Validated RoleAddReqDTO dto) {
        roleService.roleAdd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "平台角色修改")
    @PostMapping(value = RoleUrl.PLATFORM_ROLE_UPDATE)
    public Result<Void> platformRoleUpdate(@RequestBody @Validated RoleUpdateReqDTO dto) {
        roleService.roleUpdate(dto);
        return Result.success();
    }

    @ApiOperation(value = "商户角色分页列表")
    @PostMapping(value = RoleUrl.MERCHANT_ROLE_LIST_PAGE)
    public Result<PageResult<RoleListPageRespDTO>> merchantRoleListPage(@RequestBody @Validated RoleListPageReqDTO dto) {
        return Result.page(PageResult.getPageResult(roleService.roleListPage(dto)));
    }

    @SystemLog
    @ApiOperation(value = "商户角色新增")
    @PostMapping(value = RoleUrl.MERCHANT_ROLE_ADD)
    public Result<Void> merchantRoleAdd(@RequestBody @Validated RoleAddReqDTO dto) {
        roleService.roleAdd(dto);
        return Result.success();
    }

    @SystemLog
    @ApiOperation(value = "商户角色修改")
    @PostMapping(value = RoleUrl.MERCHANT_ROLE_UPDATE)
    public Result<Void> merchantRoleUpdate(@RequestBody @Validated RoleUpdateReqDTO dto) {
        roleService.roleUpdate(dto);
        return Result.success();
    }

    @ApiOperation(value = "商户角色选择")
    @PostMapping(value = RoleUrl.MERCHANT_ROLE_SELECT)
    public Result<List<MerchantRoleSelectRespDTO>> merchantRoleSelect(@RequestBody @Validated PrimaryIdDTO dto) {
        return Result.success(roleService.merchantRoleSelect(dto.getId()));
    }


}
